<?php  
/** 
 * @author alun (http://alunblog.duapp.com) 
 * @version 1.0 
 * @created 2013-5-17 
 */  
namespace App\Lib;
class RsaSecurity  
{  
private static $PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALkCFrYuJSZFB2wp
IRSrlvi2PI82g2sLBn1GKw7ziHTZ/wlOAQsWz9+B5yk3XAmcHjNECHXlTkTwhu7b
GlPTX6mXeIoVZ6Jt0DEGhEULLcz4VfxQg49R5V/wATuhJxeqlizzmSP9TYecc4bQ
0cmf3xnjZSpkoqjIEzd9YAkH8JrvAgMBAAECgYEAiul+lBvh2PJLuHLJW/Paz7RF
lGKiGmWU4csl2XwSIWrti9b+AY2HV5L6NoBSowSNyIB0udELC8huCDqLchVr5Wv8
EQFCDGqOFOPNGssq6KMIcRiG0T6wajoyczQST0nx0hUceYm51JEAVBGGdy8ffH/h
21RyfcbXJ7Oh6pUWEUECQQDa9i2fFcLS/oSlE/39wty/cqKmeHRya0x3tFJLOoHx
KwnrJBddsNjqKb3z5B+7FvibLNEYP9a7CB1viehKUFJbAkEA2E2ah8i1YP81LF0Z
L8P72D4ZsL6Zfd7/eqX9fK9DIStllng4KqT5OMazANUlbqGyVBcUDYK7HJ/7PcX9
KVVV/QJAA+b/SSaKIliG5KpGjI88f+z7GRxsdt2Sr093Z//S8QljU92AzRqpwwKb
cA1Qw3TVWW6jC1uX6B1s6N/8U9a6oQJAV0VoVeSrGcmeYJnncZg3YpYbs24Ta++v
UILsdYQZJ6bkxAMZVktdqoSw8GMPSUXAN6FgG9tlNzVtHw1lCWo+2QJAE0rMln3F
VrXuO8fS3JOBpw4NaKTDpPPvGh2zKmUe8C+nJi6I/RQeYSLT8xIpoeztlUEolxhA
zu2Oej8nhm7v0Q==
-----END PRIVATE KEY-----';  
    /** 
    *返回对应的私钥 
    */  
    private static function getPrivateKey(){  
      
        $privKey = self::$PRIVATE_KEY;  
           
        return openssl_pkey_get_private($privKey);        
    }  
   
    /** 
     * 私钥加密 
     */  
    public static function privEncrypt($data)  
    {  
        if(!is_string($data)){  
                return null;  
        }             
        return openssl_private_encrypt($data,$encrypted,self::getPrivateKey())? base64_encode($encrypted) : null;  
    }  
      
      
    /** 
     * 私钥解密 
     */  
    public static function privDecrypt($encrypted)  
    {  
        if(!is_string($encrypted)){  
                return null;  
        }  
        return (openssl_private_decrypt(base64_decode($encrypted), $decrypted, self::getPrivateKey()))? $decrypted : null;  
    }  
   
}  
   
?>  
